package com.xyazm.order.statemachine.action.order.fulfill;

import com.xyazm.common.enums.OrderStatusChangeEnum;
import com.xyazm.common.enums.OrderStatusEnum;
import com.xyazm.order.dao.OrderDeliveryDetailDAO;
import com.xyazm.order.domain.dto.AfterFulfillDTO;
import com.xyazm.order.domain.entity.OrderDeliveryDetailDO;
import com.xyazm.order.domain.entity.OrderInfoDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 订单已配送 action
 * @author xuyou
 * @date 2023年02月15日 22:04
 */
@Component
public class OrderDeliveredAction extends AbstractAfterFulfillAction {

    @Autowired
    private OrderDeliveryDetailDAO orderDeliveryDetailDAO;

    @Override
    public OrderStatusChangeEnum event() {
        return OrderStatusChangeEnum.ORDER_DELIVERED;
    }

    @Override
    protected OrderStatusEnum handleStatus() {
        return OrderStatusEnum.OUT_STOCK;
    }

    @Override
    protected void doExecute(AfterFulfillDTO afterFulfillDTO, OrderInfoDO orderInfoDO) {
        // 更新订单配送表的配送员信息
        OrderDeliveryDetailDO deliveryDetail = orderDeliveryDetailDAO.getByOrderId(orderInfoDO.getOrderId());
        orderDeliveryDetailDAO.updateDeliverer(deliveryDetail.getId(),
                afterFulfillDTO.getDelivererNo(),
                afterFulfillDTO.getDelivererName(),
                afterFulfillDTO.getDelivererPhone());
    }

}
